package com.thiruvathukal.examples.jdom;

/*
 * XML code examples by George K. Thiruvathukal. Unless noted otherwise
 * this code is covered by GPLv2. We are still working on the licensing
 * text and will update all code and documentation shortly.
 */

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Text;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

/*
 * This example shows how to use JDOM as a document builder. It should be
 * clearly evident that this is preferable to the standard DOM interfaces in
 * Java.
 */
public class JDOM1 {

	public static final String TASKS_NS = "http://www.tempuri.org";

	public static void main(String args[]) throws Exception {
		Document jdomDocument = new Document();
		Element rootElement = new Element("TaskGroup", TASKS_NS);
		jdomDocument.addContent(rootElement);
		XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());

		Element t1, t2, t3, t4, ts1, ts2;
		Text text;

		t1 = new Element("Task", TASKS_NS);
		t1.setAttribute("id", "task1");
		text = new Text("Task Description #1");
		t1.addContent(text);
		t2 = new Element("Task", TASKS_NS);
		t2.setAttribute("id", "task2");

		ts1 = new Element("TaskSeries", TASKS_NS);
		ts1.setAttribute("id", "task4");
		ts1.addContent(t1);
		text = new Text("#PCDATA Between Nested Elements");
		ts1.addContent(text);
		ts1.addContent(t2);

		rootElement.addContent(ts1);

		t3 = new Element("Task", TASKS_NS);
		t3.setAttribute("id", "task3");
		rootElement.addContent(t3);
		t4 = new Element("Task", TASKS_NS);
		t4.setAttribute("id", "task4");
		rootElement.addContent(t4);
		output.output(jdomDocument, System.out);

	}
}